package kt.com.bilin.coin.ui.dialog

import android.app.Dialog
import android.content.Context
import android.view.Gravity
import android.view.ViewGroup
import com.bilin.coin.R
import kotlinx.android.synthetic.main.dialog_app_update_hint.*
import kt.com.bilin.coin.common.getString
import kt.com.bilin.coin.common.gone
import kt.com.bilin.coin.common.visible
import org.lzh.framework.updatepluginlib.model.Update

class UpdateDownloadDialog(context: Context, update: Update) : Dialog(context, R.style.dimLoadingdialog) {
    init {
        setContentView(R.layout.dialog_app_update_hint)
        llBottom.gone()
        rlUpdateProgress.visible()
        pbUpdate.progress = 0
        tvUpdateProgress.text = getString(R.string.text_update_progress, 0)
        tvContent.text = update.updateContent
        if (update.isForced) {
            buttonLater.gone()
            setCancelable(false)
        }
        setCancelable(false)
        window?.run {
            attributes.apply {
                width = (context.resources.displayMetrics.widthPixels * 0.72).toInt()
                height = ViewGroup.LayoutParams.WRAP_CONTENT
            }
            setGravity(Gravity.CENTER)
        }
    }

    fun setProgress(progress: Int) {
        pbUpdate.progress = progress
        tvUpdateProgress.text = getString(R.string.text_update_progress, progress)
    }
}